package com.jzsqdy.mycat.thread;

import com.jzsqdy.mycat.CodeGenerator;
import com.jzsqdy.mycat.common.PointDao;
import com.jzsqdy.mycat.domain.Point;
import com.jzsqdy.mycat.domain.Statistic;

import java.util.UUID;

/**
 * 通过连接Mycat，造一批数据
 */
public class Data implements Runnable {

    private PointDao pointDao;
    private Statistic statistic;

    public Data(PointDao pointDao, Statistic statistic){
        this.pointDao = pointDao;
        this.statistic = statistic;
    }

    public double data(int length){
//        System.out.println("_____________________");
        long start = System.currentTimeMillis();
        for (int i=0;i<length;i++){
            Point point = new Point();
            point.setPointId(CodeGenerator.getRandomUID(7)+"");
            point.setMetricId(UUID.randomUUID().toString());
            String monitoredObjectId = UUID.randomUUID().toString();
            point.setMonitoredObjectId(monitoredObjectId);
            pointDao.data(point);
            if (i == 100){
                statistic.setMonitoredObjectId(monitoredObjectId);
            }
//            if(i%10000 == 0){
//                System.out.println("......................"+i);
//            }
        }
        long end = System.currentTimeMillis();
        return (end - start)*1.0/length*10000;

    }

    public void run() {
        this.data(1000000);
    }


}
